package com.whlilong.jxc.app;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.whlilong.jxc.action.AboutAction;
import com.whlilong.jxc.action.NewAction;
import com.whlilong.jxc.action.AddinfoAction;
import com.whlilong.jxc.action.CloseEditorAction;
import com.whlilong.jxc.action.DeleteAction;
import com.whlilong.jxc.action.ExitAction;
import com.whlilong.jxc.action.PrintAction;
import com.whlilong.jxc.action.RefreshAction;
import com.whlilong.jxc.action.ResetAction;
import com.whlilong.jxc.action.SaleAction;
import com.whlilong.jxc.action.SaveAction;
import com.whlilong.jxc.action.SearchAction;
import com.whlilong.jxc.action.SearchByConditonAction;
import com.whlilong.jxc.sys.SaveLogInfo;
import com.whlilong.jxc.sys.StatusBarContribution;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	private IWorkbenchAction introAction;
	
	private StatusBarContribution statusBarContribution;
	
	private Action about, reset, exit;
	//accelerator
	private Action closeEditor, add, delete, save, search, print, refresh, searchby, addinfo;


	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	protected void makeActions(IWorkbenchWindow window) {
		//配置状态拦
		String msg = "登录用户：" + SaveLogInfo.getInstance().getUsername();
		String usertag = SaveLogInfo.getInstance().getUsertag();
		usertag = usertag.equals("0")?"系统管理员":(usertag.equals("1")?"后台管理员":"前台管理员");
		msg += "\t\t身份："+usertag;
		statusBarContribution = new StatusBarContribution(msg);
		statusBarContribution.setVisible(true);
		
		introAction = ActionFactory.INTRO.create(window);
		register(introAction);
		about = new AboutAction(window);
		register(about);
		reset = new ResetAction(window);
		register(reset);
		exit = new ExitAction(window);
		register(exit);
		
		//toolbar accelerator
		closeEditor = new CloseEditorAction(window);
		register(closeEditor);
		add = new NewAction(window);
		register(add);
		delete = new DeleteAction(window);
		register(delete);
		save = new SaveAction(window);
		register(save);
		search = new SearchAction(window);
		register(search);
		print = new PrintAction(window);
		register(print);
		refresh = new RefreshAction(window);
		register(refresh);
		//条件查询
		searchby = new SearchByConditonAction(window);
		register(searchby);
		//添加按钮
		addinfo = new AddinfoAction(window);
		register(addinfo);
		

		// danganMenu
		/*districtInfo = new DistrictInfoAction(window);
		register(districtInfo);
		merchantType = new MerchantTypeAction(window);
		register(merchantType);
		businessInfo = new BusinessInfoAction(window);
		register(businessInfo);
		clientInfo = new ClientInfoAction(window);
		register(clientInfo);
		goodsInfo = new GoodsInfoAction(window);
		register(goodsInfo);
		departInfo = new DepartInfoAction(window);
		register(departInfo);
		staffInfo = new StaffInfoInfoAction(window);
		register(staffInfo);*/

	}

/*	protected void fillMenuBar(IMenuManager menuBar) {
		MenuManager fileMenu = new MenuManager("文件[&F]", "filemenu");
		menuBar.add(fileMenu);
		// Help
		fileMenu.add(reset);
		fileMenu.add(exit);

		MenuManager danganMenu = new MenuManager("档案[&D]", "danganmenu");
		menuBar.add(danganMenu);
		danganMenu.add(keshangInfo);
		danganMenu.add(keshangType);
		danganMenu.add(huoshangInfo);
		danganMenu.add(kehuoInfo);
		danganMenu.add(goodsInfo);
		danganMenu.add(partInfo);
		danganMenu.add(yuangongInfo);
		
		MenuManager caigouMenu = new MenuManager("采购[&C]", "caigoumenu");
		menuBar.add(caigouMenu);
//		caigouMenu.add(about);

		MenuManager xsMenu = new MenuManager("销售[&O]", "xsmenu");
		menuBar.add(xsMenu);
//		xsMenu.add(about);

		MenuManager kcMenu = new MenuManager("库存[&U]", "kcmenu");
		menuBar.add(kcMenu);
//		kcMenu.add(about);

		MenuManager tjMenu = new MenuManager("统计[&T]", "tjmenu");
		menuBar.add(tjMenu);
//		tjMenu.add(about);

		MenuManager glMenu = new MenuManager("管理[&L]", "glmenu");
		menuBar.add(glMenu);
//		glMenu.add(about);

		MenuManager jkMenu = new MenuManager("金卡[&K]", "jkmenu");
		menuBar.add(jkMenu);
//		jkMenu.add(about);

		MenuManager xtMenu = new MenuManager("系统[&I]", "xtmenu");
		menuBar.add(xtMenu);
//		xtMenu.add(about);

		MenuManager helpMenu = new MenuManager("帮助[&H]",
				IWorkbenchActionConstants.M_HELP);
		menuBar.add(helpMenu);
		// Help
		helpMenu.add(introAction);
	}*/

	protected void fillCoolBar(ICoolBarManager coolBar) {
		
		IToolBarManager toolBar = new ToolBarManager(SWT.FLAT | SWT.SHADOW_OUT);
		coolBar.add(toolBar);
		toolBar.add(about);
	}
	
	protected void fillStatusLine(IStatusLineManager statusLine){
		statusLine.add(statusBarContribution);
	}

}
